package com.zx.web.dao.impl;

import com.zx.bean.OrderDetail;
import com.zx.utils.DataSourceUtils;
import com.zx.web.dao.OrderDetailDao;
import org.apache.commons.dbutils.QueryRunner;

import java.sql.SQLException;

/**
 * @author 章鑫
 * @version V1.0
 * @Project 2022-09-05
 * @Package com.zx.web.dao.impl
 * @Description:
 * @Date 2022/9/15 19:29
 */
public class OrderDetailDaoImpl implements OrderDetailDao {
    @Override
    public void addOrderDetail(OrderDetail orderDetail) {
        QueryRunner qr = new QueryRunner();
        String sql = "INSERT INTO `tb_orderdetail` (`id`, `Oid`, `pid`, `num`, `Money`) VALUES (NULL, ?, ?, ?, ?);";
        try {
            qr.update(DataSourceUtils.getConnection(),sql,orderDetail.getOid(),orderDetail.getPid(),orderDetail.getNum(),orderDetail.getMoney());
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

    }

    @Override
    public void updateStatus(String id) {
        QueryRunner qr = new QueryRunner();
        String sql = "UPDATE `tb_order` SET `status` = 2 WHERE `id` = ?";
        try {
            qr.update(DataSourceUtils.getConnection(),sql,id);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
